package com.sourcegraph.cody.auth

import com.intellij.openapi.Disposable
import com.intellij.util.concurrency.annotations.RequiresEdt

/**
 * Account management service
 *
 * @param A - account type
 * @param Cred - account credentials
 */
interface AccountManager<A : Account, Cred> {

  /** Set of accounts registered within application */
  @get:RequiresEdt val accounts: Set<A>

  /** Add/update account and it's credentials */
  @RequiresEdt fun updateAccount(account: A, credentials: Cred)

  /**
   * Add/update/remove multiple accounts and their credentials Credentials are not updated if null
   * value is passed Should only be used by a bulk update from settings
   */
  @RequiresEdt fun updateAccounts(accountsWithCredentials: Map<A, Cred?>)

  /** Remove an account and clear stored credentials Does nothing if account is not present */
  @RequiresEdt fun removeAccount(account: A)

  /** Retrieve credentials for account */
  @RequiresEdt fun findCredentials(account: A): Cred?

  /** Add accounts data listener */
  @RequiresEdt fun addListener(disposable: Disposable, listener: AccountsListener<A>)
}
